package main

import (
	"ginDemo/handler/demo"
	"ginDemo/handler/translate"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"os"
	"time"
)

var log = logrus.New()

func init() {
	log.Formatter = &logrus.TextFormatter{FullTimestamp: true, TimestampFormat: time.DateTime}
	log.ReportCaller = true
	// Can be any io.Writer, see below for File example
	gin.SetMode(gin.ReleaseMode)
	log.Out = os.Stdout
	gin.DefaultWriter = log.Out
	// Only log the warning severity or above.
	log.Level = logrus.InfoLevel

}

func main() {
	//gin.SetMode(gin.DebugMode)
	engine := gin.Default()
	registerRoute(engine)
	log.Infof("server run on port 8080")
	err := engine.Run(":8080")

	if err != nil {
		log.Errorf("[main]-gin运行异常, err=%s", err)
	}
}

func registerRoute(engine *gin.Engine) {
	engine.GET("/hello", demo.HelloHandler)

	/**
	GET /translate
	{
		"textBody": "xxx",
		"sourceLanguage": (optional)
		"targetLanguage": "xxx"
	}
	*/

	engine.GET("/translate", translate.Handler)
}
